package cn.sxt.common.struts2.action;

import java.io.IOException;

import javax.servlet.http.HttpSession;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cn.sxt.common.util.VerifyCodeUtils;

/**
 * 所有Action的公共代码
 * 
 * @author wangshSxt
 *
 */
@Component("commonAction")
@Scope("prototype")
public class CommonAction extends BaseAction
{
	/**
	 * 验证码图片
	 * @return
	 * @throws IOException
	 */
	public String randImg() throws IOException
	{
		response.setHeader("Pragma", "No-cache");  
        response.setHeader("Cache-Control", "no-cache");  
        response.setDateHeader("Expires", 0);  
        response.setContentType("image/jpeg");  
          
        //生成随机字串  
        String verifyCode = VerifyCodeUtils.generateVerifyCode(4);  
        //存入会话session  
        HttpSession session = request.getSession();  
        session.setAttribute("rand", verifyCode.toLowerCase());  
        //生成图片  
        int w = 200, h = 80;  
        VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
		return null ; 
	}
}
